{% if not is_xhr|default(false) %}{% extends "base.html" %}{% endif -%}
{% block content %}
    {% set next_order = "desc" if order == "asc" else "asc" %}
    {% if order == "asc" %}
        {% set order_icon = '<span class="order-icon glyphicon glyphicon-chevron-up"></span>' %}
    {% else %}
        {% set order_icon = '<span class="order-icon glyphicon glyphicon-chevron-down"></span>' %}
    {% endif %}
    <div id="processes" class="box">
        <div class="box-header">
            <span>进程</span>
        </div>
        <div class="box-content">
            <ul class="nav nav-tabs" role="tablist">
                <li {% if filter == "all" %}class="active"{% endif %}>
                    <a href="{{ url_for(".processes", sort=sort, order=order, filter="all") }}">
                        全部进程 <span class="badge all">{{ num_procs }}</span>
                    </a>
                </li>
                <li {% if filter == "user" %}class="active"{% endif %}>
                    <a href="{{ url_for(".processes", sort=sort, order=order, filter="user") }}">
                        用户进程 <span class="badge">{{ num_user_procs }}</span>
                    </a>
                </li>
            </ul>
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>
                            <a href="{{ url_for(".processes", sort="pid", order=next_order, filter=filter) }}">PID</a>
                            {{ order_icon|safe if sort == "pid"}}
                        </th>
                        <th>
                            <a href="{{ url_for(".processes", sort="name", order=next_order, filter=filter) }}">名称</a>
                            {{ order_icon|safe if sort == "name"}}
                        </th>
                        <th>
                            <a href="{{ url_for(".processes", sort="user", order=next_order, filter=filter) }}">用户</a>
                            {{ order_icon|safe if sort == "user"}}
                        </th>
                        <th>
                            <a href="{{ url_for(".processes", sort="status", order=next_order, filter=filter) }}">状态</a>
                            {{ order_icon|safe if sort == "status"}}
                        </th>
                        <th>
                            <a href="{{ url_for(".processes", sort="created", order=next_order, filter=filter) }}">创建时间</a>
                            {{ order_icon|safe if sort == "created"}}
                        </th>
                        <th title="Resident Set Size">
                            <a href="{{ url_for(".processes", sort="mem_rss", order=next_order, filter=filter) }}">RSS</a>
                            {{ order_icon|safe if sort == "mem_rss"}}
                        </th>
                        <th title="Virtual Memory Size">
                            <a href="{{ url_for(".processes", sort="mem_vms", order=next_order, filter=filter) }}">VMS</a>
                            {{ order_icon|safe if sort == "mem_vms"}}
                        </th>
                        <th>
                            <a href="{{ url_for(".processes", sort="mem_percent", order=next_order, filter=filter) }}">内存 %</a>
                            {{ order_icon|safe if sort == "mem_percent"}}
                        </th>
                        <th>
                            <a href="{{ url_for(".processes", sort="cpu_percent", order=next_order, filter=filter) }}">CPU %</a>
                            {{ order_icon|safe if sort == "cpu_percent"}}
                        </th>
                    </tr>
                </thead>
                <tbody>
                    {% for p in processes %}
                        <tr>
                          <td>{{ p.pid }}</td>
                          <td title="{{ p.cmdline }}">
                              <a href="{{ url_for(".process", pid=p.pid) }}">{{ p.name }}</a><br/>
                              <small>{{ p.cmdline|truncate(110) }}</small>
                          </td>
                          <td>{{ p.user or "-" }}</td>
                          <td>{{ p.status }}</td>
                          <td>{{ p.created|fromtimestamp }}</td>
                          <td>{{ p.mem_rss|filesizeformat }}</td>
                          <td>{{ p.mem_vms|filesizeformat }}</td>
                          <td>{{ p.mem_percent|round }}</td>
                          <td>{{ p.cpu_percent }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
